﻿//  --------------------------------
//  Copyright (c) PK Logix LLC. All rights reserved.
//  This source code is made available under the terms of the GNU General Public License version 2 (GPLv2)
//  http://www.codeplex.com/mvcclubsite/license
//  ---------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MVCClubSite.Helpers
{
    public class CalendarHelper
    {
        public  static DateTime FirstCalendarDay(int month, int year)
        {
            DateTime firstDayOfMonth = new DateTime(year, month, 1);
            System.Globalization.Calendar cal = System.Globalization.DateTimeFormatInfo.CurrentInfo.Calendar;
            int daysFromLastMonth = ((int)cal.GetDayOfWeek(firstDayOfMonth)) - 0;
            // Always display at least one day from the previous month
            if (daysFromLastMonth <= 0)
            {
                daysFromLastMonth += 7;
            }
            return cal.AddDays(firstDayOfMonth, -daysFromLastMonth);
        }
    }
}
